# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('libtirpc' 'libtirpc-devel')
pkgver=1.1.4
pkgrel=1
pkgdesc="A port of Sun's Transport-Independent RPC library"
arch=('i686' 'x86_64')
license=('BSD')
url="https://libtirpc.sourceforge.io/"
makedepends=('gcc' 'make' 'patch' 'heimdal-devel')
source=(https://downloads.sourceforge.net/libtirpc/libtirpc-${pkgver}.tar.bz2
        0.3.2-no-undefined.patch
        0.2.4-cygwin-rpc-types.patch
        0.2.4-cygwin-pthread.patch
        1.0.2-cygwin-bindresvport.patch
        0.2.4-cygwin-ipv6.patch
        0.2.4-cygwin-poll.patch
        0.3.2-cygwin-rpcent.patch
        1.0.2-includedir.patch
        msys2-autotools.patch)
sha256sums=('2ca529f02292e10c158562295a1ffd95d2ce8af97820e3534fe1b0e3aec7561d'
            '19f6c539781476c5ac7fd58f080ca587c4c70c69dd82d57e30d69d39b9c7ac9f'
            'c247c94a431c0548610c6e97b620a3f81767a31f894b14027737b8afbade95f8'
            'd45ae803c401ca5a37e5084da822ff7f448241be38d457ef981692322e7fd057'
            'dfcd2fc7ec85b98cb6616e9b7f3168be169ed7a10b15c986917bc4cc3fc0f9da'
            '24d8f179812434e3be91800eb4387fec38d9050f3d1902ee1e66246c776fac11'
            '90cedf3f930bf44dbbed2e520305df1a53daddac464d1d68edf501466578ac0c'
            'f1bfbfda03802947253c1bc07458cbf21e826aee58aeeaed470647c559222894'
            'd349e2195da1e0c4800219da25098e6d50d344e1e8473126af4738c93f3aed47'
            '92940578daafd46f24326b802702405f60f6bcf0a6753f3552ce059dfca86111')

prepare() {
  cd libtirpc-${pkgver}
  patch -p2 -i ${srcdir}/0.3.2-no-undefined.patch
  patch -p2 -i ${srcdir}/0.2.4-cygwin-rpc-types.patch
  patch -p2 -i ${srcdir}/0.2.4-cygwin-pthread.patch
  patch -p2 -i ${srcdir}/1.0.2-cygwin-bindresvport.patch
  patch -p2 -i ${srcdir}/0.2.4-cygwin-ipv6.patch
  patch -p2 -i ${srcdir}/0.2.4-cygwin-poll.patch
  patch -p2 -i ${srcdir}/0.3.2-cygwin-rpcent.patch
  patch -p2 -i ${srcdir}/1.0.2-includedir.patch
  patch -p1 -i ${srcdir}/msys2-autotools.patch

  autoreconf -fiv
}

build() {
  cd libtirpc-${pkgver}
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --enable-gssapi

  make
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd ${pkgname}-${pkgver}
  make check
}

package_libtirpc() {
  depends=('msys2-runtime' 'gcc-libs')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/etc ${pkgdir}/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_libtirpc-devel() {
  pkgdesc="Libtirpc headers and libraries"
  groups=('development')
  depends=("libtirpc=${pkgver}")

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
